# 导包
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
# 1.导入下拉框类
from selenium.webdriver.support.select import Select

# 获取浏览器驱动
driver = webdriver.Firefox()
driver.maximize_window()
# 打开测试的网址
url = 'file:///C:/Users/tedu/Desktop/NSD2407/html/register.html'
driver.get(url)
# 切换下拉框的选项
# sleep(3)
# driver.find_element(By.CSS_SELECTOR, '[value="sh"]').click()
# # 切换到广州和重庆
# sleep(3)
# driver.find_element(By.CSS_SELECTOR, '[value="gz"]').click()
# sleep(3)
# driver.find_element(By.CSS_SELECTOR, '[value="cq"]').click()

# 定位一次找到下拉框，可以直接切换
el = driver.find_element(By.CSS_SELECTOR, '#select')
# 2.创建下拉框对象
s = Select(el)
# 2.1通过下标切换
# sleep(3)
# s.select_by_index(1)
# sleep(3)
# s.select_by_index(2)
# sleep(3)
# s.select_by_index(3)
# 2.2通过value值切换
# sleep(3)
# s.select_by_value('sh')
# sleep(3)
# s.select_by_value('gz')
# sleep(3)
# s.select_by_value('cq')
# 2.3通过显示文本切换
sleep(3)
s.select_by_visible_text('上海')
sleep(3)
s.select_by_visible_text('广州')
sleep(3)
s.select_by_visible_text('重庆')

# 停顿3秒，关闭浏览器
sleep(3)
driver.quit()